package simulation;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import operations.Operations;
import beans.Cell;

public class ForTheory {
	static Cell origin = new Cell(0, 50);
	static Cell food = new Cell(99, 50);
	static List<Cell> path = Operations.getValidPath(origin, food);

	public static void runForRandomAgents() {
		BigDecimal alpha = new BigDecimal(new Random().nextDouble()).setScale(2, RoundingMode.HALF_EVEN);
		BigDecimal beta = new BigDecimal(new Random().nextDouble()).setScale(2, RoundingMode.HALF_EVEN);
		BigDecimal gamma = new BigDecimal(new Random().nextDouble()).setScale(2, RoundingMode.HALF_EVEN);
		BigDecimal theta = new BigDecimal(new Random().nextDouble()).setScale(2, RoundingMode.HALF_EVEN);
		BigDecimal delta = new BigDecimal(new Random().nextDouble()).setScale(2, RoundingMode.HALF_EVEN);
		System.out.println(alpha + " | " + beta + " | " + gamma + " | " + theta + " | " + delta);
		List<Cell> locations = new ArrayList<Cell>();
		locations.add(Operations.plusX(origin, alpha.multiply(new BigDecimal(path.size())).intValue()));
		locations.add(Operations.plusX(origin, beta.multiply(new BigDecimal(path.size())).intValue()));
		locations.add(Operations.plusX(origin, gamma.multiply(new BigDecimal(path.size())).intValue()));
		locations.add(Operations.plusX(origin, theta.multiply(new BigDecimal(path.size())).intValue()));
		locations.add(Operations.plusX(origin, delta.multiply(new BigDecimal(path.size())).intValue()));

		new ForTheoryGUI(5, locations);
	}

	public static void runForSpecificAgents() {
		BigDecimal alpha = new BigDecimal(0).setScale(2, RoundingMode.HALF_EVEN);
		BigDecimal beta = new BigDecimal(0.15).setScale(2, RoundingMode.HALF_EVEN);
		BigDecimal gamma = new BigDecimal(0.30).setScale(2, RoundingMode.HALF_EVEN);
		BigDecimal theta = new BigDecimal(0.65).setScale(2, RoundingMode.HALF_EVEN);
		BigDecimal delta = new BigDecimal(.90).setScale(2, RoundingMode.HALF_EVEN);
		System.out.println(alpha + " | " + beta + " | " + gamma + " | " + theta + " | " + delta);
		List<Cell> locations = new ArrayList<Cell>();
		locations.add(Operations.plusX(origin, alpha.multiply(new BigDecimal(path.size())).intValue()));
		locations.add(Operations.plusX(origin, beta.multiply(new BigDecimal(path.size())).intValue()));
		locations.add(Operations.plusX(origin, gamma.multiply(new BigDecimal(path.size())).intValue()));
		locations.add(Operations.plusX(origin, theta.multiply(new BigDecimal(path.size())).intValue()));
		locations.add(Operations.plusX(origin, delta.multiply(new BigDecimal(path.size())).intValue()));
		new ForTheoryGUI(5, locations);
	}

	private static void run(int numAgents) {
		List<BigDecimal> values = new ArrayList<BigDecimal>();
		BigDecimal random;
		while (values.size() < numAgents) {
			random = new BigDecimal(new Random().nextDouble()).setScale(2, RoundingMode.HALF_EVEN);
			if (!values.contains(random))
				values.add(random);
		}
		Collections.sort(values);

		System.out.println(values);
		List<Cell> locations = new ArrayList<Cell>();
		for (int i = 0; i < numAgents; i++) {
			locations.add(Operations.plusX(origin, values.get(i).multiply(new BigDecimal(path.size())).intValue()));
		}

		new ForTheoryGUI(numAgents, locations);
	}

	public static void main(String[] args) {
		run(9);
	}

}
